package pers.jsan.litheopen.utils;

import java.security.MessageDigest;

public class SHA1Util {

    /**
     * SHA1加密
     * @param str 明文
     * @return String
     */
    public static String encryptionSHA1(String str) {
        if (str.isEmpty()) {
            return "";
        }
        MessageDigest hash = null;
        try {
            hash = MessageDigest.getInstance("SHA-1");
            byte[] bytes = hash.digest(str.getBytes("UTF-8"));
            StringBuilder result = new StringBuilder();
            for (byte b : bytes) {
                String temp = Integer.toHexString(b & 0xff);
                if (temp.length() == 1) {
                    temp = "0" + temp;
                }
                result.append(temp);
            }
            return result.toString();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "";
    }
}
